import 'package:flutter/material.dart';

import 'child_widget.dart';

class Father extends StatefulWidget {
  Father({Key key}) : super(key: key);

  @override
  _FatherState createState() => _FatherState();
}

class _FatherState extends State<Father> {
  bool _active = true;

  /*改变盒子状态*/
  void _handleTap() {
    setState(() {
      _active = !_active;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        child: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Text(
                '测试父子组件状态管理',
                style: TextStyle(color: Colors.blue, fontSize: 30),
              ),
              GestureDetector(
                onTap: _handleTap,
                child: Container(
                  width: 200,
                  height: 200,
                  alignment: Alignment.center,
                  decoration: BoxDecoration(
                      color: _active ? Colors.green : Colors.grey,
                      border: Border.all(
                          width: 10,
                          style: BorderStyle.solid,
                          color: Colors.blue),
                      borderRadius: BorderRadius.all(Radius.circular(40))),
                  child: Text(
                    '组件管理自己的状态',
                    style: TextStyle(
                        fontSize: 20,
                        color: Colors.white,
                        fontWeight: FontWeight.w900),
                  ),
                ),
              ),
              GestureDetector(
                onTap: _handleTap,
                child: ChildWidget(
                  active: _active,
                ),
              )
            ],
          ),
        ),
      ),
    );
  }
}
